package dao.impl;
import dao.ISuperUserDao;
import jdbc_util.FirstApp;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import pojo.SuperUser;
import java.sql.Connection;
import java.sql.SQLException;

public class SuperUserDaoImpl implements ISuperUserDao {
    public SuperUser findByNameAndPassWd(String name, String passwd) {
        QueryRunner qr = null;
        Connection connection = null;
        SuperUser superUser = null;
        String sql = "select * from superuser where name=? and passwd=?";
        try {
            qr=new QueryRunner();
            connection= FirstApp.getConn();
            connection.setAutoCommit(false);
            superUser = qr.query(connection, sql, new BeanHandler<>(SuperUser.class), name, passwd);
            connection.commit();

        } catch (Exception e) {
            try {
                connection.rollback();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
            e.printStackTrace();
        }
        return superUser;
    }
}
